package com.aidex.generator.mapper;

import com.aidex.common.core.domain.entity.SysMenu;
import com.aidex.generator.domain.GenTable;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.io.Serializable;
import java.util.List;

public interface GenTableMapper extends BaseMapper<GenTable> {

    @Override
    @Select("select * from gen_table ${ew.customSqlSegment}")
    @Result(column = "id", property = "columns", many = @Many(select = "com.aidex.generator.mapper.GenTableColumnMapper.selectListByTableId"))
    @Result(column = "id", property = "id")
    GenTable selectOne(@Param("ew") Wrapper<GenTable> queryWrapper);

    @Override
    @Select("select * from gen_table where id = #{id}")
    @Result(column = "id", property = "columns", many = @Many(select = "com.aidex.generator.mapper.GenTableColumnMapper.selectListByTableId"))
    @Result(column = "id", property = "id")
    GenTable selectById(Serializable id);

    @Update("${sql}")
    void addMenu(@Param("sql") String sql);

    @Select("select table_name, table_comment, create_time, update_time from information_schema.tables ${ew.customSqlSegment}")
    List<GenTable> selectDbList(@Param("ew") Wrapper<GenTable> queryWrapper);

    @Select("select * from sys_menu by id = #{id}")
    SysMenu selectSysMenuById(@Param("id") String id);

    @Select("select max(t.tree_sort) from sys_menu t where t.del_flag = 0 and t.parent_id = #{parentId}")
    Integer findSysMenuMaxSort(@Param("parentId") String parentId);

}
